package org.paradigmshift.timelapse.ui

import java.awt.Dimension

import scala.swing.event.MouseClicked
import scala.swing.Frame
import scala.swing.Table

import org.paradigmshift.timelapse.daos.IssueDao

import javax.swing.table.TableModel

class TimeLapseTable( model:TableModel ) extends Table() {
  
  override lazy val peer = new BetterJTable( model )
  
  listenTo( this.mouse.clicks )
  reactions += {
    case MouseClicked( src, point, mod, clicks, pops ) if ( clicks > 1 ) =>
      this.selection.rows.foreach( rowNum => {
        for { issue <- IssueDao.findByKey( this.apply( rowNum, 0 ).toString ) } yield {
          val issueFrame = new Frame {
            val issuePanel = new IssuePanel( issue )
            title = issue.key.getOrElse( "Unknown Jira Issue" )
            iconImage = TimeLapseUI.icon
            contents = issuePanel
            centerOnScreen
            visible = true
            val dim = new Dimension( 350, 350 )
            preferredSize = dim
            minimumSize = dim
            pack
            setLocationRelativeTo( TimeLapseTable.this )
            override def closeOperation() { issuePanel.close() }
          }
        }
      })
  }
}